import React, { useEffect, useState } from 'react'
import Item from './Item'
import Pubsub from 'pubsub-js'
export default function List() {


  //初始化一个state,请求回来数据之后setstate,
  const [searchList, setSearchList] = useState([])
  //订阅
  //拿到数据后去遍历
  useEffect(() => {
    Pubsub.subscribe('github', (_, data) => {
      // console.log(data);
      setSearchList(data.data.items)
    })
  }, [])

  return (
    <div className="row">
      {/* 数组遍历生成Item */}
      {
        searchList.map(item=>{
          return <Item key = {item.id} {...item}/>
        })
      }
    </div>
  )
}
